package com.bw.base.mvvm


import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.bw.base.entity.Res
import kotlinx.coroutines.launch


open class BaseViewModel: ViewModel() {

    fun <T> httpRequest(s: suspend ()-> Res<T>, success: (T)-> Unit){
        viewModelScope.launch {
            try {
                val res = s.invoke()
                if (res.code == 200){
                    success(res.data)
                }else{
                    Log.i("zzz", res.message)
                }
            }catch (e:Exception){
                Log.i("zzz", e.message.toString())
            }
        }
    }
}